package com.intretech.tj.global.parent;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
 * 管道父类
 * 作为管道，返回值类型应该与输入类型一致
 * 子类应该在注释中说明管道key<br/>
 * 与管道函数接收什么类型的函数
 *
 * @param <T> 输入与返回类型
 */
public class PipelineParent<T> {
    private final Map<String, Function<T, T>> pipelineMap = new ConcurrentHashMap<>();


    public void setPipeline(String key, Function<T, T> function) {
        pipelineMap.put(key, function);
    }

    public T pipeline(String key, T object) {
        if (pipelineMap.containsKey(key))
            return pipelineMap.get(key).apply(object);
        else return object;
    }
}
